//
//  MineTableViewCell.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "MineTableViewCell.h"

@implementation MineTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.titleButton];
    [self.contentView addSubview:self.arrowButton];
    [self.contentView addSubview:self.switchBtn];
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
   
}
- (void)setFrame:(CGRect)frame
{
    CGRect new = CGRectMake(10, frame.origin.y, frame.size.width - 20, frame.size.height);
    [super setFrame:new];
}
- (UIButton *)titleButton
{
    if (!_titleButton) {
        _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _titleButton.frame = CGRectMake(10, 0, 94, 53);
        _titleButton.titleLabel.font = MFontWithSize(16.f);
        [_titleButton setTitleColor:rgba(51, 51, 51, 1) forState:UIControlStateNormal];
        _titleButton.userInteractionEnabled = NO;
    
    }
    return _titleButton;
}
- (UIButton *)arrowButton
{
    if (!_arrowButton) {
        _arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _arrowButton.frame = CGRectMake((lScreenWidth - 20 - 23), 0, 8, 53);
       [_arrowButton setImage:IMAGENAMED(@"ic_mine_arrow_black") forState:UIControlStateNormal];
    
    }
    return _arrowButton;
}
- (UISwitch *)switchBtn
{
    if (!_switchBtn) {
        _switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake(lScreenWidth - 20 - 61, 0, 44, 53)];
        _switchBtn.centerY = 53/2.0;
       
    }
    return _switchBtn;
}
- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake( 0, 0, lScreenWidth - 20, 53)];
        _backView.backgroundColor = lWhiteColor;
    }
    return _backView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setData:(NSDictionary *)data
{
    _data = data;
    self.backView.hidden = YES;
    self.backgroundColor = lWhiteColor;
            [self.titleButton setTitle:data[@"title"] forState:UIControlStateNormal];
            [self.titleButton setImage:IMAGENAMED(data[@"img"]) forState:UIControlStateNormal];
    double width = [MethodTool getTextWidthWithStr:data[@"title"] font:self.titleButton.titleLabel.font ViewHeight:self.titleButton.height];
    self.titleButton.width = 30 + width;
    self.arrowButton.hidden = NO;
    self.switchBtn.hidden = YES;
    if ([data[@"title"] isEqualToString:@"护眼模式"]) {
        self.arrowButton.hidden = YES;
        self.switchBtn.hidden = NO;
        self.backView.hidden = NO;
        [self.backView setCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadius:16];
        self.contentView.backgroundColor = lClearColor;
        self.backgroundColor = lClearColor;
    }
    [self.titleButton layoutButtonWithEdgeInsetsStyle:LButtonEdgeInsetsStyleLeft imageTitleSpace:10];
  
    if ([data[@"title"] isEqualToString:@"学习设置"]) {
        self.contentView.backgroundColor = lClearColor;
        self.backgroundColor = lClearColor;
        self.backView.hidden = NO;
        [self.backView setCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadius:16];
    }
   
    if ([data[@"title"] isEqualToString:@"联系客服"]) {
        self.backgroundColor = lClearColor;
        self.backView.hidden = NO;
        [self.backView setCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadius:16];
    }
}
@end
